import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;


public class HttpClient {
    public static void main(String[] args) {
        HttpClientBuilder clientBuilder = HttpClientBuilder.create();
        HttpHost proxyTarget = new HttpHost("172.26.100.238",64000);
        clientBuilder.setProxy(proxyTarget);
        Credentials defaultcreds = new UsernamePasswordCredentials("abely_liu", "Welcome5");
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY, defaultcreds);
        clientBuilder.setDefaultCredentialsProvider(credsProvider);
        CloseableHttpClient httpClient = clientBuilder.build();
        String url ="https://github.com/search?l=&o=desc&q=language%3AJava&ref=advsearch&s=stars&type=Repositories&utf8=%E2%9C%93";
        HttpGet httpGet = new HttpGet(url);
        try {
//            System.out.println(httpClient.execute(httpGet).getStatusLine());
            System.out.println(EntityUtils.toString(httpClient.execute(httpGet).getEntity()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
